<?php
	 /* @var $this SiteController */

	 $this->pageTitle = Yii::app()->name;
?>

<?php
	 //$this->beginWidget('bootstrap.widgets.TbHeroUnit',array(
	 //'heading'=>'Welcome to '.CHtml::encode(Yii::app()->name),
//)); 
?>

<!-- <p>Congratulations! You have successfully created your Yii application.</p>

<?php //$this->endWidget();  ?>

<p>You may change the content of this page by modifying the following two files:</p>

<ul>
    <li>View file: <code><?php //echo __FILE__;              ?></code></li>
    <li>Layout file: <code><?php //echo $this->getLayoutFile('main');              ?></code></li>
</ul>

<p>For more details on how to further develop this application, please read
    the <a href="http://www.yiiframework.com/doc/">documentation</a>.
    Feel free to ask in the <a href="http://www.yiiframework.com/forum/">forum</a>,
    should you have any questions.</p> -->




<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA3xYyrj4ARm7I8UnoqfJM2H0qR5hdigac&sensor=true"></script>
<script type="text/javascript">
	var map;
	var setMapPosition = new google.maps.LatLng(-5.482482, 107.9775893);
	var jakarta = new google.maps.LatLng(-6.2297465, 106.829518);
	var bandung = new google.maps.LatLng(-6.9033101, 107.642621);
	var pondokindah = new google.maps.LatLng(-6.2703015, 106.7822402);
	var sunter = new google.maps.LatLng(-6.1371245, 106.863379);
	
	

	function initialize() {
		var mapOptions = {
			zoom: 6,
			center: setMapPosition,
			//center: new google.maps.LatLng(-5.482482, 107.9775893),
			//mapTypeId: google.maps.MapTypeId.ROADMAP
			//disableDefaultUI: 0,
			//scrollwheel: 0
		};
		//-
		var myLatlng = new google.maps.LatLng(-6.211544000000000000,106.845172000000050000);
		
		var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);

		var marker = new google.maps.Marker({
			position: myLatlng,
			title:"Hello World!"
		});

		// To add the marker to the map, call setMap();
		marker.setMap(map);
		//-
		map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
		
		$.ajax({
			url: "<?php echo Yii::app()->createUrl('/SpecialAjax/GetLocationCompany'); ?>",
			data: "username=<?php echo Yii::app()->user->getId(); ?>",
			dataType: "json",
			success: function(data) {
				if(data){
					var marker=[];					
					for (var i = 0; i < (data.one.length); i++) {						
						marker[i+1] = new google.maps.Marker({
							//position: map.getCenter(),
							position: new google.maps.LatLng(data.one[i].Latitude, data.one[i].Longitude), 
							map:map,
							title: 'Cabangz '+data.one[i].RegencyName
						});
						google.maps.event.addListener(marker[i+1], 'click', function(){						
							map.setZoom(11);
							map.setCenter(marker[i+1].getPosition());
						});
					}				
					
					for (var j = 0; j < (data.two.length); j++) {												
						marker[j+(data.one.length)+1] = new google.maps.Marker({
							//position: map.getCenter(),
							position: new google.maps.LatLng(data.two[j].Latitude, data.two[j].Longitude), 
							map:map,
							title: data.two[j].CompanyBranchName,
							id:data.two[j].LocationID
						});
						marker[j+(data.one.length)+1].setMap(null);																	
						google.maps.event.addListener(marker[j+(data.one.length)+1], 'click', function(){														
							//map.setCenter(marker[j+(data.one.length)+1].getPosition());				
							
							showCam(this.id);
						});
					}						
					/*					
					for(var h =0;h < ((i+j));h++){
						google.maps.event.addListener(map, 'zoom_changed', function() {
							var zoomLevel = map.getZoom();
							if(zoomLevel < 11)
							{
								if(h<i){									
										marker[h+1].setMap(map);									
								}else{										
										marker[h+1].setMap(null);									
										$('#cctv_area').hide();									
								}
							}
							else
							{
								if(h<i){									
										marker[h+1].setMap(map);									
								}else{										
										marker[h+1].setMap(null);									
										$('#cctv_area').hide();									
								}
								
							}							
						});	
					}*/
					google.maps.event.addListener(map, 'zoom_changed', function() {
						var zoomLevel = map.getZoom();
						if(zoomLevel < 11)
						{
							// alert(zoomLevel);
							for(var h =0;h < ((i+j));h++){
								if(h<i){				
									marker[h+1].setMap(map);									
								}else{										
									marker[h+1].setMap(null);									
									$('#cctv_area').hide();									
								}								
							}
							$('#cctv_area').hide();
						}
						else
						{
							for(var h =0;h < ((i+j));h++){
								if(h<i){								
									marker[h+1].setMap(null);
								}else{
									marker[h+1].setMap(map);								
								}
							}
							
						}
						//map.setCenter(setMapPosition);
						//infowindow.setContent('Zoom: ' + zoomLevel);
					});
					
				}
			}
		});

		
	}

	function showCam(x){
		window.location.href = "<?php echo Yii::app()->createUrl('/requestVideo/cctvshow/id'); ?>/"+x;
		
	}

	function tes(){
		//alert('yak');
		/*var c = document.getElementById("Canvas1");
		var ctx=c.getContext("2d");
		var img = new Image();
		img.src = "D:/capture/031250769.JPG";
		img.onload = ctx.drawImage(img, 0, 0);*/
	}
		
	function cek() {
		$.ajax({
			url: "<?php echo Yii::app()->createUrl('/site/getFile'); ?>",
			cache: false,
			//dataType: "json",
			success: function(msg) {
				//alert(msg);
				var c = document.getElementById("Canvas1");
				var ctx=c.getContext("2d");
				var img = new Image();
				img.src = "images/KRISOPRAS/20140314/CAMERA01/"+msg;
				//img.src = "images/031250769.JPG";
				img.onload = ctx.drawImage(img, 0, 0);
				//alert(img.src);
				//document.write('<li><a href="4thparty/KIF_0'+i+'.jpg" onclick="return !window.open(this.href);"><img src="4thpartythumbs/KIF_0'+i+'.jpg" height="54" width="72" alt="'+i+'" title="'+i+'" /></li>');
				//		document.write('<li><a href="images/'+msg+'" onclick="return !window.open(this.href);"><img src="images/'+msg+'" height="100" width="120" alt="1" title="1" /></li>');
				//$('.test').html(msg);
			}
		})
		var waktu = setTimeout("cek()",100);
	}

	$(document).ready(function(){
		//cek();
	});

	google.maps.event.addDomListener(window, 'load', initialize);
</script>
<style>
	.google-maps {
		position: relative;
		padding-bottom: 40%; /* This is the aspect ratio */
		height: 0;
		overflow: hidden;
	}
	.google-maps iframe {
		position: absolute;
		top: 0;
		left: 0;
		/*width: 100% !important;*/
		/*height: 60% !important;*/
	}
</style>
Welcome to CCTV Management System : <?php echo Sysusrsecurity::model()->find("CredentialName='" . Yii::app()->user->getId() . "'")->name; ?> |


<body onload="initialize()">
	<div class="google-maps" id="map-canvas">
		<iframe src="https://www.google.com/maps/embed?pb=!1m14!1m12!1m3!1d16326126.934178308!2d118.0148634!3d-2.5489260000000002!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!5e0!3m2!1sen!2sus!4v1400474332464" width="600" height="450" frameborder="0" style="border:0;"></iframe>
	</div>

	<div id="pilih cabang" align="center">
		</br>
		</br>

		<?php
			 $form = $this->beginWidget('bootstrap.widgets.BsActiveForm', array(
				  'layout' => BsHtml::FORM_LAYOUT_INLINE,
				  'enableAjaxValidation' => true,
				  'id' => 'picklocation-form',
				  'htmlOptions' => array(
						'class' => 'bs-example'
				  )
			 ));
			 //echo Yii::app()->user->getId();
		?>

		<?php
			 $modelProvince = Gfprovince::model();
			 $listProvince = Gfprovince::model()->findAll("isActive = '1'");
			 $dataProvince = array();

			 for ($i = 0; $i < count($listProvince); $i++) {
				 $dataProvince[$i] = $listProvince[$i]->provincename;
			 }

			 echo $form->dropDownListControlGroup($modelProvince, 'provincename', $dataProvince, array(
				  'empty' => 'City'
			 ));
		?>
		<?php
			 $modelRegency = Gfregency::model();
			 $listRegency = Gfregency::model()->findAll("isActive = '1'");
			 $dataRegency = array();

			 for ($i = 0; $i < count($listRegency); $i++) {
				 $dataRegency[$i] = $listRegency[$i]->regencyname;
			 }

			 echo $form->dropDownListControlGroup($modelRegency, 'regencyname', $dataRegency, array(
				  'empty' => 'Branch'
			 ));
		?>
		<?php
			 echo BsHtml::linkButton('Show Camera', array(
				  'color' => BsHtml::BUTTON_COLOR_PRIMARY,
				  'url' => array('/cctvcamera/index'),
			 ));
		?>
		<?php
			 $this->endWidget();
		?>
	</div>	
	<table border="1" style="display:none;">
		<tr>
			<td >

			</td>
		</tr>
		<tr>
			<td>
				searching...
			</td>
		</tr>
		<tr>
			<td>
				<div id="cctv_area" style="display: none;">
					<h2 style="text-align: center;">Tampilan CCTV (live)</h2>
					<table border="1" align="center">
						<tr>
							<td>
								<!-- <canvas id="Canvas1" width="310" height="250" style="border:1px solid #c3c3c3;">
									Web Browser Anda tidak mendukung HTML 5
								</canvas> -->
								<OBJECT classid="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921"
										  codebase="http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab"
										  width="310" height="250" id="vlc" events="True">
									<param name="Src" value="rtsp://202.142.207.150:1935/live/liveinfinity1" />
									<param name="ShowDisplay" value="True" />
									<param name="AutoLoop" value="False" />
									<param name="AutoPlay" value="True" />
									<embed id="vlcEmb"  type="application/x-google-vlc-plugin" version="VideoLAN.VLCPlugin.2" autoplay="yes" loop="no" width="310" height="250"
											 target="rtsp://169.254.49.47/panda.mkv" ></embed>
								</OBJECT>
							</td>

							<td>
								<!-- <canvas id="Canvas2" width="310" height="250" style="border:1px solid #c3c3c3;">
									Web Browser Anda tidak mendukung HTML 5
								</canvas> -->
								<OBJECT classid="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921"
										  codebase="http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab"
										  width="310" height="250" id="vlc" events="True">
									<param name="Src" value="rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov" />
									<param name="ShowDisplay" value="True" />
									<param name="AutoLoop" value="False" />
									<param name="AutoPlay" value="True" />
									<embed id="vlcEmb"  type="application/x-google-vlc-plugin" version="VideoLAN.VLCPlugin.2" autoplay="yes" loop="no" width="310" height="250"
											 target="rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov" ></embed>
								</OBJECT>
							</td>
						</tr>
					</table>
				</div>
			</td>
		</tr>
	</table>	
</body>
